package Persondata;

import org.apache.wicket.markup.html.form.Button;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;

public abstract class PersonFormPanel extends Panel {
	private static final long serialVersionUID = 1L;
	public PersonFormPanel(String id, IModel<Person> model, final String buttonLabel) {
		super(id, model);
		
		PersonForm personForm = new PersonForm("form", model);
		personForm.add(new TextField<String>("name").setRequired(true));
		personForm.add(new TextField<String>("vorname").setRequired(true));
		personForm.add(new TextField<String>("job"));
		personForm.add(new TextField<Integer>("age"));
		personForm.add(new FeedbackPanel("feedback"));
		personForm.add(new Button("buttonLabel", new Model<String>(buttonLabel)));
		add(personForm);
		
	}
	
	protected abstract void onSubmitModelHandle(final IModel<Person> model);
	
	private class PersonForm extends Form<Person> {
		private static final long serialVersionUID = 1L;

		public PersonForm(String id, IModel<Person> model) {
			super(id, model);
		}

		protected void onSubmit() {
			// *Wie* gespeichert wird, wird hier nicht definiert! Dazu muss die abstrakte äußere Klasse definiert werden. 
			onSubmitModelHandle(getModel());
		}
	}

}
